package models

import (
	"github.com/google/uuid"
	"gorm.io/gorm"
	"log"
	"server/global"
)

var db = global.MysqlDB

func init() {
	err := db.AutoMigrate(&Goods{}, &Order{})
	if err != nil {
		log.Println("建表失败", err)
		return
	}
}

type Goods struct {
	gorm.Model
	GoodsName    string `gorm:"type:varchar(30);not null;comment:商品名称" json:"goods_name"`
	GoodsPrice   string `gorm:"type:decimal(5,2);not null;comment:商品单价" json:"goods_price"`
	GoodsInquire string `gorm:"type:int(11);not null;comment:商品库存" json:"goods_inquire"`
	GoodsAddress string `gorm:"type:varchar(30);not null;comment:商品产地" json:"goods_address"`
	GoodsImg     string `gorm:"type:varchar(255);not null;comment:商品图片" json:"goods_img"`
	GoodsStatus  int    `gorm:"type:tinyint(1);check:goods_status IN (0,1);not null;comment:商品状态" json:"goods_status"`
}
type Order struct {
	gorm.Model
	Userid      int     `gorm:"type:int(11);not null;comment:用户id" json:"userid"`
	OrderSn     string  `gorm:"type:varchar(255);not null;comment:订单编号" json:"order_sn"`
	GoodsCount  float64 `gorm:"type:decimal(5,2);not null;comment:订单金额" json:"goods_count"`
	OrderStatus int     `gorm:"type:tinyint(1);check:order_status IN (0,1);not null;comment:订单状态" json:"order_status"`
}

func UUidInit() string {
	s := uuid.New()
	return s.String()
}
